package pl.lodz.p.kipme.util;

import java.util.ArrayList;
import java.util.List;

import pl.lodz.p.kipme.bo.Order;
import pl.lodz.p.kipme.bo.ProductOrder;
import pl.lodz.p.kipme.entities.OrderEntity;
import pl.lodz.p.kipme.entities.ProductOrderEntity;

public class OrderUtil {

	public static Order orderEntity2Order(OrderEntity orderEntity) {
		Order order = new Order();
		order.setDate(orderEntity.getDate());
		order.setOrderId(orderEntity.getOrderId());
		List<ProductOrder> productOrders = new ArrayList<ProductOrder>();
		for (ProductOrderEntity poe : orderEntity.getProducts()) {
			ProductOrder productOrder = new ProductOrder();
			productOrder.setNumberOfProduct(poe.getNumberOfProduct());
			productOrder.setProductId(poe.getProductId());
			productOrder.setProductOrderId(poe.getProductOrderId());
			productOrder.setStatus(poe.getStatus());
			productOrder.setComment(poe.getComment());
			productOrders.add(productOrder);
		}
		order.setProducts(productOrders);
		return order;
	}

}
